package com.cuitrip.business.order.detail.ui.model;

import com.cuitrip.business.login.LoginInstance;
import com.cuitrip.business.order.model.OrderItem;
import com.cuitrip.service.R;
import com.cuitrip.util.PlatformUtil;
import com.cuitrip.util.ResourceUtil;

import java.io.Serializable;

/**
 * Created by baziii on 15/8/10.
 */
public class SimpleServicePartRenderData implements Serializable {
    protected String serviceName;
    protected String address;
    protected String servicePic;
    protected String sid;
    protected String oid;
    protected int status;

    public SimpleServicePartRenderData(String serviceName, String servicePic,
                                       String address, String sid, String oid, int status) {
        this.serviceName = serviceName;
        this.servicePic = servicePic;
        this.address = address;
        this.sid = sid;
        this.oid = oid;
        this.status = status;
    }


    public String getOid() {
        return oid;
    }

    public void setOid(String oid) {
        this.oid = oid;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getServicePic() {
        return servicePic;
    }

    public void setServicePic(String servicePic) {
        this.servicePic = servicePic;
    }

    public String getSid() {
        return sid;
    }

    public void setSid(String sid) {
        this.sid = sid;
    }


    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public static SimpleServicePartRenderData getInstance(OrderItem orderItem) {
        SimpleServicePartRenderData result = new SimpleServicePartRenderData(orderItem.getServiceName(), orderItem.getServicePIC(),
                orderItem.getServiceAddress(), orderItem.getSid(), orderItem.getOid(), orderItem.getStatus());
        return result;
    }

    public static String getStatusText(OrderItem orderItem) {
        switch (orderItem.getStatus()) {
            case OrderItem.STATUS_WAIT_CONFIRM:
                if (LoginInstance.getInstance().getUserInfo().isTravel()) {
                    return PlatformUtil.getInstance().getString(R.string.book_state_confirm_desc_ft);
                } else {
                    return PlatformUtil.getInstance().getString(R.string.book_state_confirm_desc_fi);
                }
            case OrderItem.STATUS_WAIT_PAY:
                if (LoginInstance.getInstance().getUserInfo().isTravel()) {
                    return PlatformUtil.getInstance().getString(R.string.book_state_pay_desc_ft);
                } else {
                    return PlatformUtil.getInstance().getString(R.string.book_state_pay_desc_fi);
                }
            case OrderItem.STATUS_WAIT_START:
                if (orderItem.getLeftDays() == 1) {
                    return ResourceUtil.getString(R.string.book_state_begin_desc_tomorrow);
                } else if (orderItem.getLeftDays() == 0) {
                    return PlatformUtil.getInstance().getString(R.string.book_state_progress);
                } else {
                    return ResourceUtil.getString(R.string.book_state_begin_desc_days, orderItem.getLeftDays());
                }
            case OrderItem.STATUS_IN_PROGRESS:
                return PlatformUtil.getInstance().getString(R.string.book_state_progress);
            case OrderItem.STATUS_TRIP_FINISH:
                if (LoginInstance.getInstance().getUserInfo().isTravel()) {
                    return ResourceUtil.getString(R.string.book_state_review_ft);
                } else {
                    return ResourceUtil.getString(R.string.book_state_review_fi);
                }
            case OrderItem.STATUS_OVER:
                if (LoginInstance.getInstance().getUserInfo().isTravel()) {
                    return ResourceUtil.getString(R.string.book_state_reviewed_ft);
                } else {
                    return ResourceUtil.getString(R.string.book_state_reviewed_fi);
                }
            case OrderItem.STATUS_EXPIRED:
                //当为旅行者，这时因为退款成功失效
                if (LoginInstance.getInstance().getUserInfo().isTravel() && orderItem.getType() == OrderItem.TYPE_EXPIRED_REFUNDED) {
                    return ResourceUtil.getString(R.string.book_state_refunded);
                }
                if (orderItem.isCancelled()) {
                    return ResourceUtil.getString(R.string.book_state_cancelled);
                } else {
                    return ResourceUtil.getString(R.string.book_state_expired);
                }
            case OrderItem.STATUS_REFUND:
                if (LoginInstance.getInstance().getUserInfo().isTravel()) {
                    return ResourceUtil.getString(R.string.book_state_refund);
                } else {
                    /**
                     * 发现者退款中为cancel状态，当退款成功后为expired
                     */
                    if (orderItem.isExpired()) {
                        return PlatformUtil.getInstance().getString(R.string.book_state_expired);
                    } else {
                        return PlatformUtil.getInstance().getString(R.string.book_state_cancelled);
                    }
                }
            default:
                return orderItem.getStatusContent();
        }
    }
}
